<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录注册页面</title>
    <style>
        body,
        h1,
        form {
            margin: 0;
            padding: 0;
        }

        body {
            font-family: Arial, sans-serif;
            background-color: #f7f7f7;
        }

     .container {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

     .box {
            border: 2px solid #000;
            padding: 1px;
            height: 600px;
            width: 600px;
            background-color: #ddd;
        }

     .form-group {
            margin-bottom: 10px;
        }

     .form-group label {
            display: block;
            margin-bottom: 3px;
        }

     .form-group input {
            width: 90%;
            padding: 10px;
            border: 1px solid gray;
            border-radius: 2px;
        }

     .form-group button {
            width: 90%;
            padding: 8px;
            border: none;
            border-radius: 2px;
            background-color: green;
            color: white;
            cursor: pointer;
        }

     .form-group button:hover {
            background-color: blue;
        }

     .form-group a {
            display: block;
            text-align: center;
            margin-top: 8px;
            color: white;
            text-decoration: none;
        }

     .form-group2 a {
            display: block;
            text-align: center;
            margin-top: 8px;
            color: #337ab7;
            text-decoration: none;
        }
    </style>
</head>

<body>
    <div class="container" style="text-align: center;">
        <div class="box" id="loginForm">
            <h2>登录</h2>
            <form id="loginForm">
                <div class="form-group">
                    <label for="loginPhone">帐号</label>
                    <input type="text" id="loginPhone" name="phone" required>
                </div>
                <div class="form-group">
                    <label for="loginPassword">密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
                    <input type="password" id="loginPassword" name="password" required>
                </div>
                <div class="form-group">
                    <button type="submit">登录</button>
                </div>
                <div class="form-group2">
                    <a href="#" onclick="toggleForms()">去注册</a>
                </div>
            </form>
        </div>
        <div class="box" id="registerForm" style="display: none;" style="text-align: center;">
            <h2>注册</h2>
            <form>
                <div class="form-group">
                    <label for="registerUsername">用户名</label>
                    <input type="text" id="registerUsername" name="username" required>
                </div>
                <div class="form-group">
                    <label for="registerPhone">手机号</label>
                    <input type="text" id="registerPhone" name="phone" required>
                </div>
                <div class="form-group">
                    <label for="registerPassword">密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
                    <input type="password" id="registerPassword" name="password" required>
                </div>
                <div class="form-group">
                    <label for="registerConfirmPassword">确认密码</label>
                    <input type="password" id="registerConfirmPassword" name="confirm_password" required>
                </div>
                <div class="form-group">
                    <label for="registerEmail">邮&nbsp;&nbsp;&nbsp;&nbsp;箱</label>
                    <input type="email" id="registerEmail" name="email" required>
                </div>
                <div class="form-group">
                    <button type="submit">注册</button>
                </div>
                <div class="form-group2">
                    <a href="#" onclick="toggleForms()">去登录</a>
                </div>
            </form>
        </div>
    </div>
    <script>
        const loginErrorMessages = [
                "密码错误",
                "账户名不存在",
                "账号已被锁定，请联系客服",
                "网络异常，请稍后重试"
            ];
        
            function toggleForms() {
                var loginForm = document.getElementById('loginForm');
                var registerForm = document.getElementById('registerForm');
                if (loginForm.style.display === 'none') {
                    loginForm.style.display = 'block';
                    registerForm.style.display = 'none';
                } else {
                    loginForm.style.display = 'none';
                    registerForm.style.display = 'block';
                }
            }
        
            document.getElementById('loginForm').addEventListener('submit', function (e) {
                e.preventDefault();
                var phoneInput = document.getElementById('loginPhone');
                var passwordInput = document.getElementById('loginPassword');
                if (phoneInput.value === '') {
                    alert('帐号不能为空');
                    return;
                }
                if (passwordInput.value === '') {
                    alert('密码不能为空');
                    return;
                }
        
                // 模拟登录验证，这里简单随机返回一个错误提示（实际情况需根据真实后端交互等确定）
                const randomIndex = Math.floor(Math.random() * loginErrorMessages.length);
                const randomErrorMessage = loginErrorMessages[randomIndex];
                alert(randomErrorMessage);
            });
        
            document.querySelector('#registerForm form').addEventListener('submit', function (e) {
                e.preventDefault();
                var usernameInput = document.getElementById('registerUsername');
                var phoneInput = document.getElementById('registerPhone');
                var passwordInput = document.getElementById('registerPassword');
                var confirmPasswordInput = document.getElementById('registerConfirmPassword');
                var emailInput = document.getElementById('registerEmail');
                if (usernameInput.value === '') {
                    alert('用户名不能为空');
                    return;
                }
                if (phoneInput.value === '') {
                    alert('手机号不能为空');
                    return;
                }
                if (passwordInput.value === '') {
                    alert('密码不能为空');
                    return;
                }
                if (confirmPasswordInput.value === '') {
                    alert('确认密码不能为空');
                    return;
                }
                if (emailInput.value === '') {
                    alert('邮箱不能为空');
                    return;
                }
                var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
                if (!emailRegex.test(emailInput.value)) {
                    alert('邮箱格式不正确');
                    return;
                }
                if (passwordInput.value!== confirmPasswordInput.value) {
                    alert('两次输入的密码不一致');
                    return;
                }
            });
        </script>
    </script>
</body>

</html>
